(function ($) {
    $.get("/portal/departmentOffice/chart",(response)=>{
        let label
        let backgroundColor
        let data=[]
        //Pie Chart
        for (var key in response.departmentPeopleQuantity) {
            data.push(response.departmentPeopleQuantity[key])
        }
        console.log(data)
        label = response.departmentName;
        backgroundColor = response.departmentColor;
        new Chart(document.getElementById("pie-chart"), {
            type: 'pie',
            data: {
                labels: label,
                datasets: [{
                    label: "Population (millions)",
                    backgroundColor: backgroundColor,
                    data: data
                }]
            },
            options: {
                title: {
                    display: true,
                    text: '按部门划分的员工人数'
                }
            }
        });
        // Bar chart
        var barChart = new Chart(document.getElementById("bar-chart"), {
            type: 'bar',
            data: {
                labels: label,
                datasets: [
                    {
                        label: "员工",
                        backgroundColor: backgroundColor,
                        data: data
                    }
                ]
            },
            options: {
                legend: {display: false},
                title: {
                    display: true,
                    text: '部门员工的最大数量'
                }
            }
        });
    })
})(jQuery);
